Keyed lists


Extended Tcl defines a special type of list referred to as keyed lists. These lists provide a structured data type built upon standard Tcl lists. This provides a functionality similar to structs in the C programming language.

A keyed list is a list in which each element contains a key and value pair. These element pairs are stored as lists themselves, where the key is the first element of the list, and the value is the second. The key-value pairs are refered to as fields.

This is an example of a keyed list:

    {{NAME {Kumquat}} {TYPE {Fruit}}}

If the variable food contained the above list, then

keylget food NAME

would return {Kumquat}.

Executing the command:

keylset food PRICE {2 dollars}

would make food contain

    {{PRICE {2 dollars}} {NAME {Kumquat}} {TYPE {Fruit}}

Fields may contain subfields; `.' is the separator character. Subfields are actually fields where the value is another keyed list. Thus the following list has the top level fields NAME and PRICE, and subfields PRICE.AMOUNT and PRICE.CURRENCY:

    {NAME {Kumquat}} {PRICE {{AMOUNT {2}} {CURRENCY {dollars}}}

There is no limit to the recursive depth of subfields, allowing one to build complex data structures.

Keyed lists are constructed and accessed via a number of commands. All keyed list management commands take the name of the variable containing the keyed list as an argument (i.e. passed by reference), rather than passing the list directly.

See the manual pages for the following commands: